package com.wages.project.system.config.controller;

import com.wages.common.constant.UserConstants;
import com.wages.common.utils.StringUtils;
import com.wages.common.utils.poi.ExcelUtil;
import com.wages.framework.aspectj.lang.annotation.Log;
import com.wages.framework.aspectj.lang.enums.BusinessType;
import com.wages.framework.web.controller.BaseController;
import com.wages.framework.web.domain.AjaxResult;
import com.wages.framework.web.page.TableDataInfo;
import com.wages.project.system.config.domain.Config;
import com.wages.project.system.config.service.IConfigService;
import com.wages.project.system.user.domain.User;
import com.wages.project.system.user.service.IUserService;
import com.wages.project.system.wages.domain.Wages;
import com.wages.project.system.wages.service.IWagesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 参数配置 信息操作处理
 *
 * @author wages
 */
@Controller
@RequestMapping("/system/main")
public class SysController extends BaseController
{
    @Autowired
    private IWagesService wagesService;
    @Autowired
    private IUserService userService;
 @PostMapping()
 @ResponseBody
 public AjaxResult list(Wages wages)
 {
     startPage();
     wages.setUid(getUserId());
     if(null==wages.getTime()){
         wages.setTime(new Date());
     }
     wages.setIsok("Y");
     List<Wages> list = wagesService.selectWagesList1(wages);
     User user = userService.selectUserById(getUserId());
     BigDecimal b= user.getWages();
     if(StringUtils.isNotEmpty(list)){
         for (Wages wages1:list) {
             if(wages1.getStatus().equals("Y")){
                 b = b.add(wages1.getMonkey());
             }else {
                 b = b.subtract(wages1.getMonkey());
             }
         }

     }

     Map map = new HashMap();
     map.put("rows",list);
     map.put("wages",b);
     map.put("old",user.getWages());
     ExcelUtil<Wages> util = new ExcelUtil<Wages>(Wages.class);
     AjaxResult ajaxResult = util.exportExcel1(list,b,user.getWages(), "本月工资详情");
     return ajaxResult;
 }
}
